﻿//  Copyright (c) 2011 Ray Liang (http://www.dotnetage.com)
//  Licensed MIT: http://www.opensource.org/licenses/mit-license.php

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace DNA.Mvc
{
    /// <summary>
    /// Present the Event base class.
    /// </summary>
    public abstract class EventBase
    {
        //public EventBase() { }
        //public EventBase(HttpContextBase httpContext) { HttpContext = HttpContext; }

        /// <summary>
        /// Gets/Sets the current http context.
        /// </summary>
        public HttpContextBase HttpContext { get; set; }

        /// <summary>
        /// Gets the event name.
        /// </summary>
        public virtual string Name { get; protected set; }

        public virtual void Raise()
        {
            if (string.IsNullOrEmpty(Name))
                Name = this.GetType().ToString();

            EventDispatcher.Process(this);
        }

        /// <summary>
        /// Raise this event and notifty the observer(s) to process it.
        /// </summary>
        public virtual void Raise(HttpContextBase httpContext)
        {
            HttpContext = httpContext;
            Raise();
        }
    }


}
